/**
 * 获取意愿列表
 */
package org.morningangel.servlet.android;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.morningangel.android.bean.WillBeanList;
import org.morningangel.bean.Will;
import org.morningangel.dao.WillDao;
import org.morningangel.dao.impl.WillDaoImpl;

@WebServlet(name = "AndroidWillListServlet", urlPatterns = "/android/willList")
public class WillListServlet extends HttpServlet {
	private static final long serialVersionUID = -674955474182679071L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Integer userId = Integer.parseInt(request.getParameter("userId")); 
		WillDao willDao = new WillDaoImpl();
		List<Will> list = willDao.getByUserId(userId);
		WillBeanList result = new WillBeanList(list);
		JSONObject jsonObject = JSONObject.fromObject(result);
		PrintWriter out = response.getWriter();
		out.print(jsonObject.toString());
		out.flush();
		out.close();
	}

}
